package com.ibm.moa.outmail;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ibm.moa.outmail.adapter.ExpandableListViewAdapter;
import com.ibm.moa.outmail.adapter.ExpandableListViewAdapter.DeleteMailListener;
import com.ibm.moa.outmail.module.MailInfo;
import com.ibm.moa.outmail.net.HttpManage;
import com.ibm.moa.outmail.net.HttpRequestListener;
import com.ibm.moa.outmail.utils.DBHandler;
import com.ibm.moa.outmail.utils.MailUtils;
import com.ibm.moa.outmail.utils.ParserRequest;
import com.ibm.moa.outmail.utils.UIEventListener;
import com.ibm.moa.outmail.utils.Utils;
import com.ibm.moa.outmail.view.PullToRefresh;

public class HomeActivity extends BaseActivity implements PullToRefresh.UpdateHandle, OnClickListener, AnimationListener, HttpRequestListener,
		DeleteMailListener {
	// 收件箱变量
	private ExpandableListViewAdapter receiverAdapter;
	private ExpandableListView listView_receive;
	private PullToRefresh listLayout_receive;
	private LinearLayout footer_view_receive;
	private ProgressBar footer_probar_receive;
	private TextView footer_text_receive;
	private String refresh_time_receive = "";
	private View receiveViewRefresh;

	private List<String> timeTitlesReceive;
	private Map<Integer, List<MailInfo>> mailInfoMapReceive;
	private ArrayList<MailInfo> tempMailInfoListReceive;

	// 发件箱变量
	private ExpandableListViewAdapter mailListAdapter_send;
	private ExpandableListView listView_send;
	private PullToRefresh listLayout_send;
	private LinearLayout footer_view_send;
	private ProgressBar footer_probar_send;
	private TextView footer_text_send;
	private String refresh_time_send = "";

	private List<String> timeTitlesSend;
	private Map<Integer, List<MailInfo>> mailInfoMapSend;
	private ArrayList<MailInfo> tempMailInfoListSend;

	// 草稿箱
	private ExpandableListViewAdapter mailListAdapter_Draft;
	private ExpandableListView listView_caogao;
	private PullToRefresh listLayout_caogao;
	private LinearLayout footer_view_caogao;
	private ProgressBar footer_probar_caogao;
	private TextView footer_text_caogao;
	private String refresh_time_caogao = "";

	private List<String> timeTitlesDraft;
	private Map<Integer, List<MailInfo>> mailInfoMapDraft;
	private ArrayList<MailInfo> tempMailInfoListDraft;

	// 未读邮件
	private ExpandableListViewAdapter mailListAdapter_unread;
	private ExpandableListView listView_unread;
	private PullToRefresh listLayout_unread;
	private LinearLayout footer_view_unread;
	private ProgressBar footer_probar_unread;
	private TextView footer_text_unread;
	private String refresh_time_unread = "";
	private View unreadViewRefresh;
	private TextView tvUnreadNumber;
	private int unreadNum = 0;

	private ArrayList<String> selectedList_unread;
	private List<String> timeTitlesUnread;
	private Map<Integer, List<MailInfo>> mailInfoMapUnread;
	private ArrayList<MailInfo> tempMailInfoListUnread;

	//
	LinearLayout markLayout;
	LinearLayout menuLayout;
	Button menuSaveBackBT, menuBackBT, menuCancleBT;
	private TranslateAnimation showBackAnimation, hideBackAnimation;

	private Button baceBT;
	private ImageView backIV;
	private ImageView writeMailBT;
	// 搜索
	private LinearLayout searchMailBT;

	private ImageView ivHomeTitleArrow;
	private LinearLayout bottomMenu;
	private TranslateAnimation showMenuAnimation, hideMenuAnimation;
	private LinearLayout deleteLayout, replyLayout, forwardLayout, replyAllLayout;
	private ImageView deleteLayoutiv, replyLayoutiv, forwardLayoutiv, replyAllLayoutiv;
	private PopupWindow popupWindow;
	private LinearLayout popupView;
	private LinearLayout mailMenuLayout;
	private TextView titleMenuText;
	private RelativeLayout receiveLayoutBT, sendLayoutBT, caogaoLayoutBT, unreadLayoutBT;
	private int pageid = 1;
	private int pagesize = 10;
	private Dialog dialog;
	private boolean unreadFirst = true;
	private LinearLayout receiveLayout, sendLayout, caogaoLayout, unreadLayout;
	private DBHandler db;

	@SuppressLint("SimpleDateFormat")
	private SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日   HH:mm:ss     ");

	@SuppressLint("HandlerLeak")
	@SuppressWarnings("unchecked")
	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			isLoadMore = false;
			if (dialog != null) {
				dialog.dismiss();
				dialog = null;
			}
			switch (msg.what) {
			case UIEventListener.EVENT_SHOW_BOTTON_MENU:
				if (!bottomMenu.isShown()) {
					bottomMenu.setVisibility(View.VISIBLE);
					bottomMenu.startAnimation(showMenuAnimation);
					if (receiveLayout.isShown() || unreadLayout.isShown() || sendLayout.isShown()) {
						deleteLayout.setVisibility(View.VISIBLE);
						replyLayout.setVisibility(View.VISIBLE);
						forwardLayout.setVisibility(View.VISIBLE);
						replyAllLayout.setVisibility(View.VISIBLE);
					} else {
						deleteLayout.setVisibility(View.VISIBLE);
						replyLayout.setVisibility(View.INVISIBLE);
						forwardLayout.setVisibility(View.INVISIBLE);
						replyAllLayout.setVisibility(View.INVISIBLE);
					}

				}
				break;
			case UIEventListener.EVENT_HIDE_BOTTON_MENU:
				if (bottomMenu.isShown()) {
					bottomMenu.startAnimation(hideMenuAnimation);
				}
				break;
			case UIEventListener.EVENT_SHOW_BUTTON:
				if (receiveLayout.isShown() || unreadLayout.isShown() || sendLayout.isShown()) {
					replyLayout.setVisibility(View.VISIBLE);
					forwardLayout.setVisibility(View.VISIBLE);
					replyAllLayout.setVisibility(View.VISIBLE);
				} else {
					replyLayout.setVisibility(View.INVISIBLE);
					forwardLayout.setVisibility(View.INVISIBLE);
					replyAllLayout.setVisibility(View.INVISIBLE);
				}
				break;
			case UIEventListener.EVENT_HIDE_BUTTON:
				replyLayout.setVisibility(View.INVISIBLE);
				forwardLayout.setVisibility(View.INVISIBLE);
				replyAllLayout.setVisibility(View.INVISIBLE);
				break;
			case 1:
				listLayout_receive.endUpdate("");
				break;

			case UIEventListener.EVENT_GET_DATA_FEFRESH_SUCCESS:
				HashMap<String, String> map = (HashMap<String, String>) msg.obj;
				if (map != null) {
					// 移除之前的FootView
					listView_receive.removeFooterView(receiveViewRefresh);

					if ("1".equals(map.get("req_code"))) {
						int total = 0;
						String mail_cnt = map.get("mail_cnt");
						try {
							total = Integer.valueOf(mail_cnt);
						} catch (Exception e) {
							total = -1;
						}

						// 清空之前的数据
						mailInfoMapReceive.clear();

						// 将临时的List集合中的数据拷贝到Map集合中
						Utils.copyMailList2MailMap(tempMailInfoListReceive, mailInfoMapReceive, timeTitlesReceive);

						if (receiverAdapter == null) {
							receiverAdapter = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesReceive, mailInfoMapReceive,
									HomeActivity.this);
							listView_receive.setAdapter(receiverAdapter);

							for (int i = 0; i < listView_receive.getCount(); i++) {
								listView_receive.expandGroup(i);
							}
						} else {
							receiverAdapter.notifyDataSetChanged();
							for (int i = 0; i < listView_receive.getCount(); i++) {
								listView_receive.expandGroup(i);
							}
						}

						// 修改未读邮件的数量
						changeUnreadNumber();

						if (total <= 0) {
							listLayout_receive.setVisibility(View.GONE);
							TextView nodataTV = (TextView) findViewById(R.id.receive_no_data_tv);
							nodataTV.setVisibility(View.VISIBLE);
						} else {
							listLayout_receive.setVisibility(View.VISIBLE);
							TextView nodataTV = (TextView) findViewById(R.id.receive_no_data_tv);
							nodataTV.setVisibility(View.GONE);
						}

						if (Utils.getMapSize(mailInfoMapReceive) == total) {
							if (listView_receive.getFooterViewsCount() > 0) {
								listView_receive.removeFooterView(footer_view_receive);
							}
						} else {
							if (listView_receive.getFooterViewsCount() < 1) {
								listView_receive.addFooterView(footer_view_receive);
							}
						}

						Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
						refresh_time_receive = formatter.format(curDate);
						// listLayout_receive.endUpdate(refresh_time_receive);
					} else {
						Toast.makeText(HomeActivity.this, (String) map.get("req_mess") == null ? "返回信息错误" : (map.get("req_mess") + ""),
								Toast.LENGTH_SHORT).show();
						// listLayout_receive.endUpdate(refresh_time_receive);

						// 没有数据也让其下拉刷新
						showReceivePullRefresh();
					}
				}
				listLayout_receive.endUpdate(refresh_time_receive);
				break;
			case UIEventListener.EVENT_GET_DATA_MORE_SUCCESS:
				HashMap<String, String> mapMore = (HashMap<String, String>) msg.obj;
				if (mapMore != null) {
					if ("1".equals(mapMore.get("req_code"))) {
						int totalMore = 0;
						try {
							totalMore = Integer.valueOf(mapMore.get("mail_cnt"));
						} catch (Exception e) {
							totalMore = -1;
						}

						// 将临时集合中的数据拷贝到Map集合中
						Utils.copyMailList2MailMap(tempMailInfoListReceive, mailInfoMapReceive, timeTitlesReceive);

						if (receiverAdapter == null) {
							receiverAdapter = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesReceive, mailInfoMapReceive,
									HomeActivity.this);
							listView_receive.setAdapter(receiverAdapter);

							for (int i = 0; i < listView_receive.getCount(); i++) {
								listView_receive.expandGroup(i);
							}
						} else {
							receiverAdapter.notifyDataSetChanged();
							for (int i = 0; i < listView_receive.getCount(); i++) {
								listView_receive.expandGroup(i);
							}
						}

						// 修改未读邮件的数量
						changeUnreadNumber();

						if (totalMore == 0) {
							listLayout_receive.setVisibility(View.GONE);
							TextView nodataTV = (TextView) findViewById(R.id.receive_no_data_tv);
							nodataTV.setVisibility(View.VISIBLE);
						} else {
							listLayout_receive.setVisibility(View.VISIBLE);
							TextView nodataTV = (TextView) findViewById(R.id.receive_no_data_tv);
							nodataTV.setVisibility(View.GONE);
						}

						if (Utils.getMapSize(mailInfoMapReceive) == totalMore) {
							if (listView_receive.getFooterViewsCount() > 0) {
								listView_receive.removeFooterView(footer_view_receive);
							}
						} else {
							if (listView_receive.getFooterViewsCount() < 1) {
								listView_receive.addFooterView(footer_view_receive);
							}
						}
						// footer_probar_receive.setVisibility(View.GONE);
						// footer_text_receive.setText("更多");
					} else {
						Toast.makeText(HomeActivity.this,
								(String) mapMore.get("req_mess") == null ? "返回信息错误" : ("返回信息错误:" + mapMore.get("req_mess") + ""), Toast.LENGTH_SHORT)
								.show();
						// footer_probar_receive.setVisibility(View.GONE);
						// footer_text_receive.setText("更多");
					}
				}
				footer_probar_receive.setVisibility(View.GONE);
				footer_text_receive.setText("更多");
				break;
			case UIEventListener.EVENT_GET_DATA_FEFRESH_FAILURE:
				listLayout_receive.endUpdate(refresh_time_receive);

				showReceivePullRefresh();

				Toast.makeText(HomeActivity.this, (String) msg.obj, Toast.LENGTH_SHORT).show();
				break;
			case UIEventListener.EVENT_GET_DATA_MORE_FAILURE:
				footer_probar_receive.setVisibility(View.GONE);
				footer_text_receive.setText("更多");
				Toast.makeText(HomeActivity.this, (String) msg.obj, Toast.LENGTH_SHORT).show();
				break;
			case UIEventListener.EVENT_GET_UNREAD_DATA_FEFRESH_SUCCESS:
				HashMap<String, String> caogaomap = (HashMap<String, String>) msg.obj;

				if (caogaomap != null) {
					// 移除之前的FootView
					listView_unread.removeFooterView(unreadViewRefresh);

					if ("1".equals(caogaomap.get("req_code"))) {
						int total = 0;
						String mail_cnt = caogaomap.get("mail_cnt");
						try {
							total = Integer.valueOf(mail_cnt);
						} catch (Exception e) {
							total = -1;
						}

						mailInfoMapUnread.clear();

						// 将临时的List集合中的数据拷贝到Map集合中
						Utils.copyMailList2MailMap(tempMailInfoListUnread, mailInfoMapUnread, timeTitlesUnread);

						if (mailListAdapter_unread == null) {
							mailListAdapter_unread = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesUnread, mailInfoMapUnread,
									HomeActivity.this);
							listView_unread.setAdapter(mailListAdapter_unread);

							for (int i = 0; i < listView_unread.getCount(); i++) {
								listView_unread.expandGroup(i);
							}
						} else {
							mailListAdapter_unread.notifyDataSetChanged();
							for (int i = 0; i < listView_unread.getCount(); i++) {
								listView_unread.expandGroup(i);
							}
						}

						// 修改未读邮件的数量
						unreadNum = Utils.getMapSize(mailInfoMapUnread);
						// 将未读邮件的数量显示在文本框中
						showUnreadNumOnTextView();

						if (total == 0) {
							listLayout_unread.setVisibility(View.GONE);
							TextView nodataTV = (TextView) findViewById(R.id.unread_no_data_tv);
							nodataTV.setVisibility(View.VISIBLE);
						} else {
							listLayout_unread.setVisibility(View.VISIBLE);
							TextView nodataTV = (TextView) findViewById(R.id.unread_no_data_tv);
							nodataTV.setVisibility(View.GONE);
						}

						if (Utils.getMapSize(mailInfoMapUnread) == total) {
							if (listView_unread.getFooterViewsCount() > 0) {
								listView_unread.removeFooterView(footer_view_unread);
							}
						} else {
							if (listView_unread.getFooterViewsCount() < 1) {
								listView_unread.addFooterView(footer_view_unread);
							}
						}

						Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
						refresh_time_unread = formatter.format(curDate);
						// listLayout_unread.endUpdate(refresh_time_unread);
						if (selectedList_unread.size() > 0) {
							selectedList_unread.clear();
							if (mailListAdapter_unread != null) {
								mailListAdapter_unread.notifyDataSetChanged();
							}
							if (bottomMenu.isShown()) {
								bottomMenu.startAnimation(hideMenuAnimation);
							}
						}
					} else {
						Toast.makeText(HomeActivity.this, (String) caogaomap.get("req_mess") == null ? "返回信息错误" : (caogaomap.get("req_mess") + ""),
								Toast.LENGTH_SHORT).show();
						// listLayout_unread.endUpdate(refresh_time_unread);

						// 没有数据也让其下拉刷新
						showUnreadPullRefresh();
					}
				}
				listLayout_unread.endUpdate(refresh_time_unread);
				break;
			case UIEventListener.EVENT_GET_UNREAD_DATA_MORE_SUCCESS:
				HashMap<String, String> caogaomapMore = (HashMap<String, String>) msg.obj;
				if (caogaomapMore != null) {
					if ("1".equals(caogaomapMore.get("req_code"))) {
						int totalMore = 0;
						try {
							totalMore = Integer.valueOf(caogaomapMore.get("mail_cnt"));
						} catch (Exception e) {
							totalMore = -1;
						}

						// 将临时的List集合中的数据拷贝到Map集合中
						Utils.copyMailList2MailMap(tempMailInfoListUnread, mailInfoMapUnread, timeTitlesUnread);

						if (mailListAdapter_unread == null) {
							mailListAdapter_unread = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesUnread, mailInfoMapUnread,
									HomeActivity.this);
							listView_unread.setAdapter(mailListAdapter_unread);

							for (int i = 0; i < listView_unread.getCount(); i++) {
								listView_unread.expandGroup(i);
							}
						} else {
							mailListAdapter_unread.notifyDataSetChanged();
							for (int i = 0; i < listView_unread.getCount(); i++) {
								listView_unread.expandGroup(i);
							}
						}

						// 修改未读邮件的数量
						unreadNum = Utils.getMapSize(mailInfoMapUnread);
						// 将未读邮件的数量显示在文本框中
						showUnreadNumOnTextView();

						if (totalMore == 0) {
							listLayout_unread.setVisibility(View.GONE);
							TextView nodataTV = (TextView) findViewById(R.id.unread_no_data_tv);
							nodataTV.setVisibility(View.VISIBLE);
						} else {
							listLayout_unread.setVisibility(View.VISIBLE);
							TextView nodataTV = (TextView) findViewById(R.id.receive_no_data_tv);
							nodataTV.setVisibility(View.GONE);
						}

						if (Utils.getMapSize(mailInfoMapUnread) == totalMore) {
							if (listView_unread.getFooterViewsCount() > 0) {
								listView_unread.removeFooterView(footer_view_unread);
							}
						} else {
							if (listView_unread.getFooterViewsCount() < 1) {
								listView_unread.addFooterView(footer_view_unread);
							}
						}
						// footer_probar_unread.setVisibility(View.GONE);
						// footer_text_unread.setText("更多");
					} else {
						Toast.makeText(HomeActivity.this,
								(String) caogaomapMore.get("req_mess") == null ? "返回信息错误" : (caogaomapMore.get("req_mess") + ""), Toast.LENGTH_SHORT)
								.show();
						// footer_probar_unread.setVisibility(View.GONE);
						// footer_text_unread.setText("更多");
					}
				}
				footer_probar_unread.setVisibility(View.GONE);
				footer_text_unread.setText("更多");
				break;
			case UIEventListener.EVENT_GET_UNREAD_DATA_FEFRESH_FAILURE:

				// 没有数据也让其下拉刷新
				listLayout_unread.endUpdate(refresh_time_unread);
				showUnreadPullRefresh();

				Toast.makeText(HomeActivity.this, (String) msg.obj, Toast.LENGTH_SHORT).show();
				break;
			case UIEventListener.EVENT_GET_UNREAD_DATA_MORE_FAILURE:
				footer_probar_unread.setVisibility(View.GONE);
				footer_text_unread.setText("更多");
				Toast.makeText(HomeActivity.this, (String) msg.obj, Toast.LENGTH_SHORT).show();
				break;
			case UIEventListener.EVENT_GET_CAOGAO_DATA_FEFRESH_SUCCESS:
				mailInfoMapDraft.clear();

				// 拷贝数据
				Utils.copyMailList2MailMap(tempMailInfoListDraft, mailInfoMapDraft, timeTitlesDraft);

				if (mailListAdapter_Draft == null) {
					mailListAdapter_Draft = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesDraft, mailInfoMapDraft, HomeActivity.this);
					listView_caogao.setAdapter(mailListAdapter_Draft);

					for (int i = 0; i < listView_caogao.getCount(); i++) {
						listView_caogao.expandGroup(i);
					}
				} else {
					mailListAdapter_Draft.notifyDataSetChanged();
					for (int i = 0; i < listView_caogao.getCount(); i++) {
						listView_caogao.expandGroup(i);
					}
				}

				if (Utils.getMapSize(mailInfoMapDraft) == 0) {
					listLayout_caogao.setVisibility(View.GONE);
					TextView nodataTV = (TextView) findViewById(R.id.caogao_no_data_tv);
					nodataTV.setVisibility(View.VISIBLE);
				} else {
					listLayout_caogao.setVisibility(View.VISIBLE);
					TextView nodataTV = (TextView) findViewById(R.id.caogao_no_data_tv);
					nodataTV.setVisibility(View.GONE);
				}

				if (Utils.getMapSize(mailInfoMapDraft) < 10) {
					if (listView_caogao.getFooterViewsCount() > 0) {
						listView_caogao.removeFooterView(footer_view_caogao);
					}
				} else {
					if (listView_caogao.getFooterViewsCount() < 1) {
						listView_caogao.addFooterView(footer_view_caogao);
					}
				}

				Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
				refresh_time_caogao = formatter.format(curDate);
				listLayout_caogao.endUpdate(refresh_time_caogao);
				break;
			case UIEventListener.EVENT_GET_CAOGAO_DATA_MORE_SUCCESS:
				// 拷贝数据
				Utils.copyMailList2MailMap(tempMailInfoListDraft, mailInfoMapDraft, timeTitlesDraft);

				if (mailListAdapter_Draft == null) {
					mailListAdapter_Draft = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesDraft, mailInfoMapDraft, HomeActivity.this);
					listView_caogao.setAdapter(mailListAdapter_Draft);

					for (int i = 0; i < listView_caogao.getCount(); i++) {
						listView_caogao.expandGroup(i);
					}
				} else {
					mailListAdapter_Draft.notifyDataSetChanged();
					for (int i = 0; i < listView_caogao.getCount(); i++) {
						listView_caogao.expandGroup(i);
					}
				}

				if (Utils.getMapSize(mailInfoMapDraft) == 0) {
					listLayout_caogao.setVisibility(View.GONE);
					TextView nodataTV = (TextView) findViewById(R.id.caogao_no_data_tv);
					nodataTV.setVisibility(View.VISIBLE);
				} else {
					listLayout_caogao.setVisibility(View.VISIBLE);
					TextView nodataTV = (TextView) findViewById(R.id.caogao_no_data_tv);
					nodataTV.setVisibility(View.GONE);
				}

				if (Utils.getMapSize(mailInfoMapDraft) == db.getCaoGaoCount()) {
					if (listView_caogao.getFooterViewsCount() > 0) {
						listView_caogao.removeFooterView(footer_view_send);
					}
				} else {
					if (listView_caogao.getFooterViewsCount() < 1) {
						listView_caogao.addFooterView(footer_view_send);
					}
				}

				footer_probar_caogao.setVisibility(View.GONE);
				footer_text_caogao.setText("更多");
				break;
			case UIEventListener.EVENT_DELETE_RECEIVE_MAIL_SUCCESS:
				HashMap<String, Object> mapDelete = (HashMap<String, Object>) msg.obj;
				if (mapDelete != null) {
					if ("1".equals(mapDelete.get("req_code"))) {
						if (bottomMenu.isShown()) {
							bottomMenu.startAnimation(hideMenuAnimation);
						}
						Toast.makeText(HomeActivity.this, (String) mapDelete.get("req_mess") == null ? "删除成功" : (mapDelete.get("req_mess") + ""),
								Toast.LENGTH_SHORT).show();

						getRefrushMailListRequest();
						dialog = Utils.createProgressDialog(HomeActivity.this, Utils.getLoadingMessage(HomeActivity.this, "加载中..."));
						dialog.show();
					} else {
						Toast.makeText(HomeActivity.this, (String) mapDelete.get("req_mess") == null ? "返回信息错误" : (mapDelete.get("req_mess") + ""),
								Toast.LENGTH_SHORT).show();
					}
				}
				break;
			case UIEventListener.EVENT_DELETE_RECEIVE_MAIL_FAILURE:
				Toast.makeText(HomeActivity.this, (String) msg.obj, Toast.LENGTH_SHORT).show();
				break;
			case UIEventListener.EVENT_DELETE_UNREAD_MAIL_SUCCESS:
				HashMap<String, Object> mapUDelete = (HashMap<String, Object>) msg.obj;
				if (mapUDelete != null) {
					if ("1".equals(mapUDelete.get("req_code"))) {
						if (bottomMenu.isShown()) {
							bottomMenu.startAnimation(hideMenuAnimation);
						}
						Toast.makeText(HomeActivity.this, (String) mapUDelete.get("req_mess") == null ? "删除成功" : (mapUDelete.get("req_mess") + ""),
								Toast.LENGTH_SHORT).show();
						getUnreadMailList();
						dialog = Utils.createProgressDialog(HomeActivity.this, Utils.getLoadingMessage(HomeActivity.this, "加载中..."));
						dialog.show();
					} else {
						Toast.makeText(HomeActivity.this, (String) mapUDelete.get("req_mess") == null ? "返回信息错误" : (mapUDelete.get("req_mess") + ""),
								Toast.LENGTH_SHORT).show();
					}
				}
				break;
			case UIEventListener.EVENT_DELETE_UNREAD_MAIL_FAILURE:
				Toast.makeText(HomeActivity.this, (String) msg.obj, Toast.LENGTH_SHORT).show();
				break;
			case UIEventListener.EVENT_GET_SEND_DATA_FEFRESH_SUCCESS:
				mailInfoMapSend.clear();

				// 将临时集合中的数据拷贝到Map集合中
				Utils.copyMailList2MailMap(tempMailInfoListSend, mailInfoMapSend, timeTitlesSend);

				if (mailListAdapter_send == null) {
					mailListAdapter_send = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesSend, mailInfoMapSend, HomeActivity.this);
					listView_send.setAdapter(mailListAdapter_send);

					for (int i = 0; i < listView_send.getCount(); i++) {
						listView_send.expandGroup(i);
					}
				} else {
					mailListAdapter_send.notifyDataSetChanged();
					for (int i = 0; i < listView_send.getCount(); i++) {
						listView_send.expandGroup(i);
					}
				}

				if (Utils.getMapSize(mailInfoMapSend) == 0) {
					listLayout_send.setVisibility(View.GONE);
					TextView nodataTV = (TextView) findViewById(R.id.send_no_data_tv);
					nodataTV.setVisibility(View.VISIBLE);
				} else {
					listLayout_send.setVisibility(View.VISIBLE);
					TextView nodataTV = (TextView) findViewById(R.id.send_no_data_tv);
					nodataTV.setVisibility(View.GONE);
				}

				if (Utils.getMapSize(mailInfoMapSend) < 10) {
					if (listView_send.getFooterViewsCount() > 0) {
						listView_send.removeFooterView(footer_view_send);
					}
				} else {
					if (listView_send.getFooterViewsCount() < 1) {
						listView_send.addFooterView(footer_view_send);
					}
				}

				Date curDate_send = new Date(System.currentTimeMillis());// 获取当前时间
				refresh_time_send = formatter.format(curDate_send);
				listLayout_send.endUpdate(refresh_time_send);
				break;
			case UIEventListener.EVENT_GET_SEND_DATA_MORE_SUCCESS:
				// 将临时集合中的数据拷贝到Map集合中
				Utils.copyMailList2MailMap(tempMailInfoListSend, mailInfoMapSend, timeTitlesSend);

				if (mailListAdapter_send == null) {
					mailListAdapter_send = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesSend, mailInfoMapSend, HomeActivity.this);
					listView_send.setAdapter(mailListAdapter_send);

					for (int i = 0; i < listView_send.getCount(); i++) {
						listView_send.expandGroup(i);
					}
				} else {
					mailListAdapter_send.notifyDataSetChanged();
					for (int i = 0; i < listView_send.getCount(); i++) {
						listView_send.expandGroup(i);
					}
				}

				if (Utils.getMapSize(mailInfoMapSend) == 0) {
					listLayout_send.setVisibility(View.GONE);
					TextView nodataTV = (TextView) findViewById(R.id.send_no_data_tv);
					nodataTV.setVisibility(View.VISIBLE);
				} else {
					listLayout_send.setVisibility(View.VISIBLE);
					TextView nodataTV = (TextView) findViewById(R.id.send_no_data_tv);
					nodataTV.setVisibility(View.GONE);
				}

				if (Utils.getMapSize(mailInfoMapSend) == db.getSendCount()) {
					if (listView_send.getFooterViewsCount() > 0) {
						listView_send.removeFooterView(footer_view_send);
					}
				} else {
					if (listView_send.getFooterViewsCount() < 1) {
						listView_send.addFooterView(footer_view_send);
					}
				}

				footer_probar_send.setVisibility(View.GONE);
				footer_text_send.setText("更多");
				break;
			default:
				break;
			}

		}
	};

	// 修改未读邮件的数量
	private void changeUnreadNumber() {
		Set<Integer> keySets = mailInfoMapReceive.keySet();
		if (null != keySets && 0 < keySets.size()) {
			unreadNum = 0;
			for (Integer key : keySets) {
				List<MailInfo> list = mailInfoMapReceive.get(key);
				if (null != list && list.size() > 0) {
					for (MailInfo mailInfo : list) {
						if ("false".equals(mailInfo.readFlag)) {
							unreadNum++;
						}
					}
				}
			}
		}

		// 将未读邮件的数量显示在文本框中
		showUnreadNumOnTextView();
	}

	/**
	 * 将未读邮件的数量显示在文本框中
	 */
	private void showUnreadNumOnTextView() {
		if (unreadNum > 0) {
			tvUnreadNumber.setText(unreadNum + "");
		} else {
			tvUnreadNumber.setText("");
		}
	}

	private void showUnreadPullRefresh() {
		if (mailListAdapter_unread == null) {
			mailListAdapter_unread = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesUnread, mailInfoMapUnread, HomeActivity.this);
			listView_unread.setAdapter(mailListAdapter_unread);

			for (int i = 0; i < listView_unread.getCount(); i++) {
				listView_unread.expandGroup(i);
			}

			listView_unread.removeFooterView(footer_view_unread);
			listView_unread.addFooterView(unreadViewRefresh);
		} else {
			mailListAdapter_unread.notifyDataSetChanged();
		}
	}

	private void showReceivePullRefresh() {
		// 没有数据也让其下拉刷新
		if (receiverAdapter == null) {
			receiverAdapter = new ExpandableListViewAdapter(HomeActivity.this, timeTitlesReceive, mailInfoMapReceive, HomeActivity.this);
			listView_receive.setAdapter(receiverAdapter);

			for (int i = 0; i < listView_receive.getCount(); i++) {
				listView_receive.expandGroup(i);
			}

			listView_receive.removeFooterView(footer_view_receive);
			listView_receive.addFooterView(receiveViewRefresh);
		} else {
			receiverAdapter.notifyDataSetChanged();
		}
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		Utils.deleteDirectory(MailApplication.fileSaveDir);
		String usercode = getIntent().getStringExtra("userName") == null ? "" : getIntent().getStringExtra("userName");
		String passWord = getIntent().getStringExtra("password") == null ? "" : getIntent().getStringExtra("password");
		if (usercode != null) {
			if (!usercode.contains("@")) {
				MailApplication.provider = MailUtils.getProviderByDomail("bj.chinamobile.com");
			} else {
				int index = usercode.indexOf("@");
				String domain = usercode.substring(index + 1);
				usercode = usercode.substring(0, index);
				MailApplication.provider = MailUtils.getProviderByDomail(domain);
			}
		} else {
			usercode = "";
		}

		MailApplication.userCode = usercode;
		MailApplication.passWord = passWord;
		db = new DBHandler(this);

		initView();

		// 显示标题旁边的箭头
		ivHomeTitleArrow.setBackgroundResource(R.drawable.circle_down);

		initReceiveMailView();
		initSendMailView();
		initCaoGaoBoxView();
		initUnreadBoxView();

		getRefrushMailListRequest();
		// getUnreadMailList();
		dialog = Utils.createProgressDialog(this, Utils.getLoadingMessage(HomeActivity.this, "加载中..."));
		dialog.show();
	}

	@Override
	public void onClick(View v) {
		if (v == baceBT) {
			finish();
		} else if (v == backIV) {
			if (null != popupWindow && popupWindow.isShowing()) {
				dismissPopupWindow();
			} else {
				finish();
			}
		} else if (v == writeMailBT) {
			Intent intent = new Intent(HomeActivity.this, MailActivity.class);
			startActivity(intent);
		} else if (v == searchMailBT) {
			Intent intent = new Intent(HomeActivity.this, SearchActivity.class);
			startActivity(intent);
		} else if (v == mailMenuLayout) {
			if (popupWindow.isShowing()) {
				dismissPopupWindow();
			} else {
				showPopupWindow();
			}
		} else if (v == footer_view_receive) {
			getMoreMailListRequest();
			footer_probar_receive.setVisibility(View.VISIBLE);
			footer_text_receive.setText("获取数据...");
		} else if (v == footer_view_unread) {
			getMoreUnreadMailList();
			footer_probar_unread.setVisibility(View.VISIBLE);
			footer_text_unread.setText("获取数据...");
		} else if (v == footer_view_caogao) {
			getMoreCaoGaoList();
		} else if (v == footer_view_send) {
			getMoreSendList();
		} else if (v == receiveLayoutBT) {
			dismissPopupWindow();

			titleMenuText.setText("收件箱");
			receiveLayout.setVisibility(View.VISIBLE);
			sendLayout.setVisibility(View.GONE);
			caogaoLayout.setVisibility(View.GONE);
			unreadLayout.setVisibility(View.GONE);
		} else if (v == sendLayoutBT) {
			dismissPopupWindow();

			titleMenuText.setText("发件箱");
			receiveLayout.setVisibility(View.GONE);
			sendLayout.setVisibility(View.VISIBLE);
			caogaoLayout.setVisibility(View.GONE);
			unreadLayout.setVisibility(View.GONE);
			// if(sendFirst){
			getSendMailList();
			dialog = Utils.createProgressDialog(this, Utils.getLoadingMessage(HomeActivity.this, "加载中..."));
			dialog.show();
			// sendFirst = false;
			// }

		} else if (v == caogaoLayoutBT) {
			dismissPopupWindow();

			titleMenuText.setText("草稿箱");
			receiveLayout.setVisibility(View.GONE);
			sendLayout.setVisibility(View.GONE);
			caogaoLayout.setVisibility(View.VISIBLE);
			unreadLayout.setVisibility(View.GONE);
			// if(caogaoFirst){
			getCaoGaoMailList();
			dialog = Utils.createProgressDialog(this, Utils.getLoadingMessage(HomeActivity.this, "加载中..."));
			dialog.show();
			// caogaoFirst = false;
			// }
		} else if (v == unreadLayoutBT) {
			dismissPopupWindow();

			titleMenuText.setText("未读邮件");
			receiveLayout.setVisibility(View.GONE);
			sendLayout.setVisibility(View.GONE);
			caogaoLayout.setVisibility(View.GONE);
			unreadLayout.setVisibility(View.VISIBLE);
			if (unreadFirst) {
				getUnreadMailList();
				dialog = Utils.createProgressDialog(this, Utils.getLoadingMessage(HomeActivity.this, "加载中..."));
				dialog.show();
				unreadFirst = false;
			}
			if (selectedList_unread.size() == 0) {
				bottomMenu.setVisibility(View.GONE);
				deleteLayout.setVisibility(View.VISIBLE);
				replyLayout.setVisibility(View.VISIBLE);
				forwardLayout.setVisibility(View.VISIBLE);
				replyAllLayout.setVisibility(View.VISIBLE);
			} else if (selectedList_unread.size() == 1) {
				deleteLayout.setVisibility(View.VISIBLE);
				replyLayout.setVisibility(View.VISIBLE);
				forwardLayout.setVisibility(View.VISIBLE);
				replyAllLayout.setVisibility(View.VISIBLE);
				if (!bottomMenu.isShown()) {
					bottomMenu.setVisibility(View.VISIBLE);
					bottomMenu.startAnimation(showMenuAnimation);
				}
			} else if (selectedList_unread.size() > 0) {
				deleteLayout.setVisibility(View.VISIBLE);
				replyLayout.setVisibility(View.INVISIBLE);
				forwardLayout.setVisibility(View.INVISIBLE);
				replyAllLayout.setVisibility(View.INVISIBLE);
				if (!bottomMenu.isShown()) {
					bottomMenu.setVisibility(View.VISIBLE);
					bottomMenu.startAnimation(showMenuAnimation);
				}
			}
		} else if (v == replyLayout || v == replyLayoutiv) {
			if (unreadLayout.isShown()) {
				if (selectedList_unread.size() == 1) {
					Intent intent = new Intent(HomeActivity.this, MailActivity.class);
					intent.putExtra("mailId", selectedList_unread.get(0));
					intent.putExtra("mailType", 1);
					intent.putExtra("getData", true);
					startActivity(intent);
				} else {
					Toast.makeText(HomeActivity.this, "请选择一条邮件", Toast.LENGTH_SHORT).show();
				}
			}
		} else if (v == replyAllLayout || v == replyAllLayoutiv) {
			if (receiveLayout.isShown()) {
				if (unreadLayout.isShown()) {
					if (selectedList_unread.size() == 1) {
						Intent intent = new Intent(HomeActivity.this, MailActivity.class);
						intent.putExtra("mailId", selectedList_unread.get(0));
						intent.putExtra("mailType", 2);
						intent.putExtra("getData", true);
						startActivity(intent);
					} else {
						Toast.makeText(HomeActivity.this, "请选择一条邮件", Toast.LENGTH_SHORT).show();
					}
				}
			}
		} else if (v == forwardLayout || v == forwardLayoutiv) {
			if (receiveLayout.isShown()) {
				if (unreadLayout.isShown()) {
					if (selectedList_unread.size() == 1) {
						Intent intent = new Intent(HomeActivity.this, MailActivity.class);
						intent.putExtra("mailId", selectedList_unread.get(0));
						intent.putExtra("mailType", 3);
						intent.putExtra("getData", true);
						startActivity(intent);
					} else {
						Toast.makeText(HomeActivity.this, "请选择一条邮件", Toast.LENGTH_SHORT).show();
					}
				}
			}
		} else if (v == deleteLayout || v == deleteLayoutiv) {
			AlertDialog.Builder dialog = new AlertDialog.Builder(HomeActivity.this).setTitle("删除提示").setMessage("确定删除选中邮件")
					.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialogInterface, int which) {
							if (unreadLayout.isShown()) {
								if (selectedList_unread.size() > 0) {
									String mailIds = "";
									for (int i = 0; i < selectedList_unread.size(); i++) {
										if (i == (selectedList_unread.size() - 1)) {
											mailIds += selectedList_unread.get(i);
										} else {
											mailIds += selectedList_unread.get(i) + ",";
										}
									}

									HashMap<String, String> map = new HashMap<String, String>();
									map.put("invoke", "deleteMail");
									map.put("userCode", MailApplication.userCode);
									map.put("password", MailApplication.passWord);
									map.put("mailIds", mailIds);
									new HttpManage(HomeActivity.this, HomeActivity.this, map, 6);
									HomeActivity.this.dialog = Utils.createProgressDialog(HomeActivity.this,
											Utils.getLoadingMessage(HomeActivity.this, "删除邮件..."));
									HomeActivity.this.dialog.show();
								}
							}
						}
					}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
						}
					});
			dialog.show();

		} else if (v == menuCancleBT) {
			menuLayout.startAnimation(hideBackAnimation);
		} else if (v == menuSaveBackBT) {
			Utils.deleteDirectory(MailApplication.fileSaveDir);
			finish();
		} else if (v == menuBackBT) {
			finish();
		}
	}

	/**
	 * 关闭PopupWindow
	 */
	private void dismissPopupWindow() {
		popupWindow.dismiss();
		ivHomeTitleArrow.setBackgroundResource(R.drawable.circle_down);
	}

	/**
	 * 显示PopupWindow
	 */
	private void showPopupWindow() {
		popupWindow.showAsDropDown(mailMenuLayout);
		ivHomeTitleArrow.setBackgroundResource(R.drawable.circle_up);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		Utils.deleteDirectory(MailApplication.fileSaveDir);
	}

	private void getSendMailList() {
		new Thread() {
			public void run() {
				tempMailInfoListSend = db.getSendMailList(System.currentTimeMillis());
				handler.sendEmptyMessage(UIEventListener.EVENT_GET_SEND_DATA_FEFRESH_SUCCESS);
			}
		}.start();
	}

	private void getMoreSendList() {
		new Thread() {
			public void run() {
				tempMailInfoListSend = db.getSendMailList(getTimeMills(mailInfoMapSend));
				handler.sendEmptyMessage(UIEventListener.EVENT_GET_SEND_DATA_MORE_SUCCESS);
			}
		}.start();
	}

	private void getMoreCaoGaoList() {
		new Thread() {
			public void run() {
				tempMailInfoListDraft = db.getCaoGaoList(getTimeMills(mailInfoMapDraft));
				handler.sendEmptyMessage(UIEventListener.EVENT_GET_CAOGAO_DATA_MORE_SUCCESS);
			}
		}.start();
	}

	/*
	 * 获取给定Map集合中最后一个元素的MailInfo的timeMillis的值
	 */
	private long getTimeMills(Map<Integer, List<MailInfo>> mailInfoMap) {
		long result = 0;

		if (null != mailInfoMap && mailInfoMap.size() > 0) {
			List<MailInfo> list = mailInfoMap.get(mailInfoMap.size() - 1);
			if (null != list && list.size() > 0) {
				MailInfo mailInfo = list.get(list.size() - 1);
				result = mailInfo.timeMillis;
			}
		}

		return result;
	}

	private void getCaoGaoMailList() {
		new Thread() {
			public void run() {
				tempMailInfoListDraft = db.getCaoGaoList(System.currentTimeMillis());
				handler.sendEmptyMessage(UIEventListener.EVENT_GET_CAOGAO_DATA_FEFRESH_SUCCESS);
			}
		}.start();
	}

	private void getUnreadMailList() {
		pageid = 1;
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("invoke", "searchMail");
		map.put("userCode", MailApplication.userCode);
		map.put("password", MailApplication.passWord);
		map.put("searchCond", "");
		map.put("pageNo", pageid + "");
		map.put("pageSize", pagesize + "");
		map.put("readFlag", "1");
		new HttpManage(this, this, map, 3);
	}

	private void getMoreUnreadMailList() {
		++pageid;
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("invoke", "searchMail");
		map.put("userCode", MailApplication.userCode);
		map.put("password", MailApplication.passWord);
		map.put("searchCond", "");
		map.put("pageNo", pageid + "");
		map.put("pageSize", pagesize + "");
		map.put("readFlag", "1");
		new HttpManage(this, this, map, 4);
	}

	@Override
	public void onUpdate() {
		if (receiveLayout.isShown()) {
			getRefrushMailListRequest();
		} else if (unreadLayout.isShown()) {
			getUnreadMailList();
		} else if (caogaoLayout.isShown()) {
			getCaoGaoMailList();
		} else if (sendLayout.isShown()) {
			getSendMailList();
		}
	}

	@Override
	public void onAnimationStart(Animation animation) {
	}

	@Override
	public void onAnimationEnd(Animation animation) {
		if (animation == showMenuAnimation) {
			bottomMenu.setVisibility(View.VISIBLE);
		} else if (animation == hideMenuAnimation) {
			bottomMenu.setVisibility(View.GONE);
		} else

		if (animation == showBackAnimation) {
			markLayout.setVisibility(View.VISIBLE);
			menuLayout.setVisibility(View.VISIBLE);
		} else if (animation == hideBackAnimation) {
			markLayout.setVisibility(View.GONE);
			menuLayout.setVisibility(View.GONE);
		}
	}

	@Override
	public void onAnimationRepeat(Animation animation) {
	}

	private void getRefrushMailListRequest() {
		pageid = 1;
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("invoke", "getImailList");
		map.put("userCode", MailApplication.userCode);
		map.put("password", MailApplication.passWord);
		map.put("searchCond", "");
		map.put("pageNo", pageid + "");
		map.put("pageSize", pagesize + "");
		new HttpManage(this, this, map, 1);
	}

	private boolean isLoadMore = false;

	private void getMoreMailListRequest() {
		if (!isLoadMore) {
			++pageid;
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("invoke", "getImailList");
			map.put("userCode", MailApplication.userCode);
			map.put("password", MailApplication.passWord);
			map.put("searchCond", "");
			map.put("pageNo", pageid + "");
			map.put("pageSize", pagesize + "");
			new HttpManage(this, this, map, 2);
		}
		isLoadMore = true;
	}

	private void initView() {
		markLayout = (LinearLayout) findViewById(R.id.mail_mask_view);
		markLayout.setVisibility(View.GONE);
		markLayout.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (markLayout.isShown()) {
					menuLayout.startAnimation(hideBackAnimation);
					return true;
				}
				return true;
			}
		});
		menuLayout = (LinearLayout) findViewById(R.id.mail_menu_layout);
		menuLayout.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				return true;
			}
		});
		menuLayout.setVisibility(View.GONE);

		menuSaveBackBT = (Button) findViewById(R.id.mail_menu_save_back_bt);
		menuBackBT = (Button) findViewById(R.id.mail_menu_back_bt);
		menuCancleBT = (Button) findViewById(R.id.mail_info_menu_cancle_bt);
		menuSaveBackBT.setOnClickListener(this);
		menuBackBT.setOnClickListener(this);
		menuCancleBT.setOnClickListener(this);
		showBackAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1,
				Animation.RELATIVE_TO_SELF, 0);
		showBackAnimation.setDuration(300);
		hideBackAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
				Animation.RELATIVE_TO_SELF, 1);
		hideBackAnimation.setDuration(300);
		showBackAnimation.setAnimationListener(this);
		hideBackAnimation.setAnimationListener(this);

		// title的菜单
		backIV = (ImageView) findViewById(R.id.home_back_iv);
		backIV.setOnClickListener(this);
		mailMenuLayout = (LinearLayout) findViewById(R.id.home_mail_menu_layout);
		mailMenuLayout.setOnClickListener(this);
		titleMenuText = (TextView) findViewById(R.id.home_title_select_tv);
		ivHomeTitleArrow = (ImageView) findViewById(R.id.home_title_arrow);
		popupView = (LinearLayout) View.inflate(this, R.layout.mail_menu_layout, null);
		popupWindow = new PopupWindow(popupView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		popupWindow.setAnimationStyle(R.style.popupwindow_animation);
		popupWindow.setTouchable(true);

		receiveLayoutBT = (RelativeLayout) popupView.findViewById(R.id.mail_menu_receive_layout);
		sendLayoutBT = (RelativeLayout) popupView.findViewById(R.id.mail_menu_send_layout);
		caogaoLayoutBT = (RelativeLayout) popupView.findViewById(R.id.mail_menu_caogao_layout);
		unreadLayoutBT = (RelativeLayout) popupView.findViewById(R.id.mail_menu_weidu_layout);
		tvUnreadNumber = (TextView) popupView.findViewById(R.id.tv_unread_number);

		popupView.setOnTouchListener(new OnTouchListener() {

			float downX = 0;
			float downY = 0;

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				float x = event.getX();
				float y = event.getY();

				switch (event.getAction()) {
				case MotionEvent.ACTION_DOWN:
					downX = x;
					downY = y;

					break;
				case MotionEvent.ACTION_UP:

					float deltaX = x - downX;
					float deltaY = y - downY;
					if (Math.abs(deltaY) > 50) {// 向上滑动，关闭PopupWindow
						dismissPopupWindow();
						break;
					}

					if (Math.abs(deltaY) < 15 && Math.abs(deltaX) < 15) {// 是一次点击，也关闭PopupWindow
						dismissPopupWindow();
					}

					break;
				default:
					break;
				}

				return false;
			}
		});

		receiveLayoutBT.setOnClickListener(this);
		sendLayoutBT.setOnClickListener(this);
		caogaoLayoutBT.setOnClickListener(this);
		unreadLayoutBT.setOnClickListener(this);

		// 四个大布局
		receiveLayout = (LinearLayout) findViewById(R.id.home_receive_layout);
		sendLayout = (LinearLayout) findViewById(R.id.home_send_layout);
		caogaoLayout = (LinearLayout) findViewById(R.id.home_caogao_layout);
		unreadLayout = (LinearLayout) findViewById(R.id.home_unread_layout);

		// title写邮件
		writeMailBT = (ImageView) findViewById(R.id.home_write_mail_bt);
		writeMailBT.setOnClickListener(this);
		// title搜索
		searchMailBT = (LinearLayout) findViewById(R.id.home_search_mail);
		searchMailBT.setOnClickListener(this);

		// 底部操作菜单
		bottomMenu = (LinearLayout) findViewById(R.id.home_bottom_menu_layout);
		deleteLayout = (LinearLayout) findViewById(R.id.home_delete_mail_layout);
		replyLayout = (LinearLayout) findViewById(R.id.home_reply_mail_layout);
		forwardLayout = (LinearLayout) findViewById(R.id.home_forward_mail_layout);
		replyAllLayout = (LinearLayout) findViewById(R.id.home_reply_all_mail_layout);
		deleteLayout.setOnClickListener(this);
		replyLayout.setOnClickListener(this);
		forwardLayout.setOnClickListener(this);
		replyAllLayout.setOnClickListener(this);
		deleteLayoutiv = (ImageView) findViewById(R.id.home_delete_mail_layout_iv);
		replyLayoutiv = (ImageView) findViewById(R.id.home_reply_mail_layout_iv);
		forwardLayoutiv = (ImageView) findViewById(R.id.home_forward_mail_layout_iv);
		replyAllLayoutiv = (ImageView) findViewById(R.id.home_reply_all_mail_layout_iv);
		deleteLayoutiv.setOnClickListener(this);
		replyLayoutiv.setOnClickListener(this);
		forwardLayoutiv.setOnClickListener(this);
		replyAllLayoutiv.setOnClickListener(this);
		// 底部操作菜单显隐动画
		showMenuAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1,
				Animation.RELATIVE_TO_SELF, 0);
		showMenuAnimation.setDuration(200);
		hideMenuAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
				Animation.RELATIVE_TO_SELF, 1);
		hideMenuAnimation.setDuration(200);
		showMenuAnimation.setAnimationListener(this);
		hideMenuAnimation.setAnimationListener(this);
	}

	private void initReceiveMailView() {
		listLayout_receive = (PullToRefresh) findViewById(R.id.home_receive_mail_list_layout);
		listLayout_receive.setUpdateHandle(this);
		listView_receive = (ExpandableListView) findViewById(R.id.home_receive_mail_list);
		footer_view_receive = (LinearLayout) View.inflate(this, R.layout.listview_footer_view, null);
		footer_probar_receive = (ProgressBar) footer_view_receive.findViewById(R.id.listview_footer_view_progressbar);
		footer_text_receive = (TextView) footer_view_receive.findViewById(R.id.listview_footer_view_text);
		footer_view_receive.setOnClickListener(this);
		listView_receive.addFooterView(footer_view_receive);
		receiveViewRefresh = new View(HomeActivity.this);
		listView_receive.setOnGroupClickListener(new OnGroupClickListener() {

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
				// TODO Auto-generated method stub
				return true;
			}
		});
		listView_receive.setOnScrollListener(new OnScrollListener() {
			private boolean isBottom = false;
			private int prevState = 0;

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				if (prevState != SCROLL_STATE_IDLE && scrollState == SCROLL_STATE_IDLE && isBottom) {
					if (listView_receive.getFooterViewsCount() > 0) {
						footer_view_receive.performClick();
					}
				}
				prevState = scrollState;
			}

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
				if (firstVisibleItem + visibleItemCount >= totalItemCount) {
					isBottom = true;
				} else {
					isBottom = false;
				}
			}
		});

		timeTitlesReceive = new ArrayList<String>();
		mailInfoMapReceive = new TreeMap<Integer, List<MailInfo>>();
		tempMailInfoListReceive = new ArrayList<MailInfo>();
	}

	private void initSendMailView() {
		listView_send = (ExpandableListView) findViewById(R.id.home_send_mail_list);
		listLayout_send = (PullToRefresh) findViewById(R.id.home_send_mail_list_layout);
		listLayout_send.setUpdateHandle(this);
		footer_view_send = (LinearLayout) View.inflate(this, R.layout.listview_footer_view, null);
		footer_probar_send = (ProgressBar) footer_view_send.findViewById(R.id.listview_footer_view_progressbar);
		footer_text_send = (TextView) footer_view_send.findViewById(R.id.listview_footer_view_text);
		footer_view_send.setOnClickListener(this);
		listView_send.addFooterView(footer_view_send);
		listView_send.setOnGroupClickListener(new OnGroupClickListener() {

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
				// TODO Auto-generated method stub
				return true;
			}
		});
		listView_send.setOnScrollListener(new OnScrollListener() {
			private boolean isBottom = false;
			private int prevState = 0;

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				if (prevState != SCROLL_STATE_IDLE && scrollState == SCROLL_STATE_IDLE && isBottom) {
					if (listView_send.getFooterViewsCount() > 0) {
						footer_view_send.performClick();
					}
				}
				prevState = scrollState;
			}

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
				if (firstVisibleItem + visibleItemCount >= totalItemCount) {
					isBottom = true;
				} else {
					isBottom = false;
				}
			}
		});

		timeTitlesSend = new ArrayList<String>();
		mailInfoMapSend = new TreeMap<Integer, List<MailInfo>>();
		tempMailInfoListSend = new ArrayList<MailInfo>();
	}

	private void initCaoGaoBoxView() {
		listLayout_caogao = (PullToRefresh) findViewById(R.id.home_caogao_mail_list_layout);
		listLayout_caogao.setUpdateHandle(this);
		listView_caogao = (ExpandableListView) findViewById(R.id.home_caogao_mail_list);
		footer_view_caogao = (LinearLayout) View.inflate(this, R.layout.listview_footer_view, null);
		footer_probar_caogao = (ProgressBar) footer_view_caogao.findViewById(R.id.listview_footer_view_progressbar);
		footer_text_caogao = (TextView) footer_view_caogao.findViewById(R.id.listview_footer_view_text);
		listView_caogao.addFooterView(footer_view_caogao);
		footer_view_caogao.setOnClickListener(this);
		listView_caogao.setOnGroupClickListener(new OnGroupClickListener() {

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
				// TODO Auto-generated method stub
				return true;
			}
		});
		listView_caogao.setOnScrollListener(new OnScrollListener() {
			private boolean isBottom = false;
			private int prevState = 0;

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				if (prevState != SCROLL_STATE_IDLE && scrollState == SCROLL_STATE_IDLE && isBottom) {
					if (listView_caogao.getFooterViewsCount() > 0) {
						footer_view_caogao.performClick();
					}
				}
				prevState = scrollState;
			}

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
				if (firstVisibleItem + visibleItemCount >= totalItemCount) {
					isBottom = true;
				} else {
					isBottom = false;
				}
			}
		});

		timeTitlesDraft = new ArrayList<String>();
		tempMailInfoListDraft = new ArrayList<MailInfo>();
		mailInfoMapDraft = new TreeMap<Integer, List<MailInfo>>();
	}

	private void initUnreadBoxView() {
		listLayout_unread = (PullToRefresh) findViewById(R.id.home_unread_mail_list_layout);
		listLayout_unread.setUpdateHandle(this);
		listView_unread = (ExpandableListView) findViewById(R.id.home_unread_mail_list);
		footer_view_unread = (LinearLayout) View.inflate(this, R.layout.listview_footer_view, null);
		footer_probar_unread = (ProgressBar) footer_view_unread.findViewById(R.id.listview_footer_view_progressbar);
		footer_text_unread = (TextView) footer_view_unread.findViewById(R.id.listview_footer_view_text);
		listView_unread.addFooterView(footer_view_unread);
		footer_view_unread.setOnClickListener(this);
		unreadViewRefresh = new View(HomeActivity.this);
		listView_unread.setOnGroupClickListener(new OnGroupClickListener() {

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
				// TODO Auto-generated method stub
				return true;
			}
		});
		listView_unread.setOnScrollListener(new OnScrollListener() {
			private boolean isBottom = false;
			private int prevState = 0;

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				if (prevState != SCROLL_STATE_IDLE && scrollState == SCROLL_STATE_IDLE && isBottom) {
					if (listView_unread.getFooterViewsCount() > 0) {
						footer_view_unread.performClick();
					}
				}
				prevState = scrollState;
			}

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
				if (firstVisibleItem + visibleItemCount >= totalItemCount) {
					isBottom = true;
				} else {
					isBottom = false;
				}
			}
		});

		selectedList_unread = new ArrayList<String>();
		timeTitlesUnread = new ArrayList<String>();
		mailInfoMapUnread = new TreeMap<Integer, List<MailInfo>>();
		tempMailInfoListUnread = new ArrayList<MailInfo>();
	}

	@Override
	public void action(int actionCode, String resultStr, int httpFlag) {
		switch (actionCode) {
		case HttpRequestListener.EVENT_GET_DATA_SUCCESS:
			Log.i("lgs", resultStr);
			switch (httpFlag) {
			case 1:
				try {
					HashMap<String, String> map = ParserRequest.ParsReceiveMailList(resultStr, tempMailInfoListReceive);
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_GET_DATA_FEFRESH_SUCCESS, map);
					moreMeg.sendToTarget();
				} catch (Exception e) {
					e.printStackTrace();
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_GET_DATA_FEFRESH_FAILURE, "返回信息错误");
					moreMeg.sendToTarget();
				}
				break;
			case 2:
				try {
					HashMap<String, String> map = ParserRequest.ParsReceiveMailList(resultStr, tempMailInfoListReceive);
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_GET_DATA_MORE_SUCCESS, map);
					moreMeg.sendToTarget();
				} catch (Exception e) {
					e.printStackTrace();
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_GET_DATA_MORE_FAILURE, "返回信息错误");
					moreMeg.sendToTarget();
				}
				break;
			case 3:
				try {
					HashMap<String, String> map = ParserRequest.ParsReceiveMailList(resultStr, tempMailInfoListUnread);
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_GET_UNREAD_DATA_FEFRESH_SUCCESS, map);
					moreMeg.sendToTarget();
				} catch (Exception e) {
					e.printStackTrace();
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_GET_UNREAD_DATA_FEFRESH_FAILURE, "返回信息错误");
					moreMeg.sendToTarget();
				}
				break;
			case 4:
				try {
					HashMap<String, String> map = ParserRequest.ParsReceiveMailList(resultStr, tempMailInfoListUnread);
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_GET_UNREAD_DATA_MORE_SUCCESS, map);
					moreMeg.sendToTarget();
				} catch (Exception e) {
					e.printStackTrace();
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_GET_UNREAD_DATA_MORE_FAILURE, "返回信息错误");
					moreMeg.sendToTarget();
				}
				break;
			case 5:
				try {
					HashMap<String, Object> map = ParserRequest.ParsSendMail(resultStr);
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_DELETE_RECEIVE_MAIL_SUCCESS, map);
					moreMeg.sendToTarget();
				} catch (Exception e) {
					e.printStackTrace();
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_DELETE_RECEIVE_MAIL_FAILURE, "返回信息错误");
					moreMeg.sendToTarget();
				}
				break;
			case 6:
				try {
					HashMap<String, Object> map = ParserRequest.ParsSendMail(resultStr);
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_DELETE_UNREAD_MAIL_SUCCESS, map);
					moreMeg.sendToTarget();
				} catch (Exception e) {
					e.printStackTrace();
					Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_DELETE_UNREAD_MAIL_FAILURE, "返回信息错误");
					moreMeg.sendToTarget();
				}
				break;
			}
			break;
		case HttpRequestListener.EVENT_GET_DATA_FAIL:
			switch (httpFlag) {
			case 1:
				Message moreMeg = handler.obtainMessage(UIEventListener.EVENT_GET_DATA_FEFRESH_FAILURE, "获取网络信息失败");
				moreMeg.sendToTarget();
				break;
			case 2:
				Message moreMeg1 = handler.obtainMessage(UIEventListener.EVENT_GET_DATA_MORE_FAILURE, "获取网络信息失败");
				moreMeg1.sendToTarget();
				break;
			case 3:
				Message moreMeg3 = handler.obtainMessage(UIEventListener.EVENT_GET_UNREAD_DATA_FEFRESH_FAILURE, "获取网络信息失败");
				moreMeg3.sendToTarget();
				break;
			case 4:
				Message moreMeg4 = handler.obtainMessage(UIEventListener.EVENT_GET_UNREAD_DATA_MORE_FAILURE, "获取网络信息失败");
				moreMeg4.sendToTarget();
				break;
			case 5:
				Message moreMeg5 = handler.obtainMessage(UIEventListener.EVENT_DELETE_RECEIVE_MAIL_FAILURE, "获取网络信息失败");
				moreMeg5.sendToTarget();
				break;
			case 6:
				Message moreMeg6 = handler.obtainMessage(UIEventListener.EVENT_DELETE_UNREAD_MAIL_FAILURE, "获取网络信息失败");
				moreMeg6.sendToTarget();
			}
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
			case 1:
				getCaoGaoMailList();
				break;
			case 11:
				if (data != null && data.getStringExtra("mailId") != null) {
					String mailId = data.getStringExtra("mailId");
					for (int i = 0; i < mailInfoMapReceive.size(); i++) {
						for (int j = 0; null != mailInfoMapReceive.get(i) && j < mailInfoMapReceive.get(i).size(); j++) {
							if (mailId.equals(mailInfoMapReceive.get(i).get(j).mailId)) {
								mailInfoMapReceive.remove(i);
								break;
							}
						}
					}

					if (receiverAdapter != null) {
						receiverAdapter.notifyDataSetChanged();
					}
					getRefrushMailListRequest();
					dialog = Utils.createProgressDialog(this, Utils.getLoadingMessage(HomeActivity.this, "加载中..."));
					dialog.show();
				}
				break;
			case 12:
				if (data != null && data.getStringExtra("mailId") != null) {
					for (int i = 0; i < mailInfoMapUnread.size(); i++) {
						for (int j = 0; null != mailInfoMapUnread.get(i) && j < mailInfoMapUnread.get(i).size(); j++) {
							if (data.getStringExtra("mailId").equals(mailInfoMapUnread.get(i).get(j).mailId)) {
								mailInfoMapUnread.remove(i);
								break;
							}
						}
					}

					if (mailListAdapter_unread != null) {
						mailListAdapter_unread.notifyDataSetChanged();
					}
					getUnreadMailList();
					dialog = Utils.createProgressDialog(this, Utils.getLoadingMessage(HomeActivity.this, "加载中..."));
					dialog.show();
				}
				break;
			case 13:
				if (data != null) {
					Long time = data.getLongExtra("timeMillis", -1);
					for (int i = 0; i < mailInfoMapSend.size(); i++) {
						List<MailInfo> list = mailInfoMapSend.get(i);
						for (MailInfo mailInfo : list) {
							if (time == mailInfo.timeMillis) {
								mailInfoMapSend.get(i).remove(mailInfo);
								break;
							}
						}
					}

					if (mailListAdapter_send != null) {
						mailListAdapter_send.notifyDataSetChanged();
					}
				}
				break;
			default:
				break;
			}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// if(keyCode == event.KEYCODE_BACK) {
		// if(markLayout.isShown()){
		// menuLayout.startAnimation(hideBackAnimation);
		// return true;
		// }else{
		// menuLayout.setVisibility(View.VISIBLE);
		// menuLayout.startAnimation(showBackAnimation);
		// return true;
		// }
		// }

		// 在PopupWindow显示的时候，点击返回按钮，只是隐藏PopupWindow，别的什么也不做
		if (keyCode == KeyEvent.KEYCODE_BACK && null != popupWindow && popupWindow.isShowing()) {
			dismissPopupWindow();

			return true;
		}

		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void deleteMail(final MailInfo mailInfo) {
		AlertDialog.Builder dialog = new AlertDialog.Builder(HomeActivity.this).setTitle("删除提示").setMessage("确定删除选中邮件")
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialogInterface, int which) {
						if (caogaoLayout.isShown()) {
							// 删除数据库中的数据
							ArrayList<Long> timeMillises = new ArrayList<Long>();
							timeMillises.add(mailInfo.timeMillis);
							db.deleteCaoGao(timeMillises);
							for (int i = 0; i < mailInfoMapDraft.size(); i++) {
								List<MailInfo> list = mailInfoMapDraft.get(i);
								for (int j = 0; null != list && j < list.size(); j++) {
									if (mailInfo.timeMillis == list.get(j).timeMillis) {
										mailInfoMapDraft.get(i).remove(j);
										break;
									}
								}
							}

							mailListAdapter_Draft.notifyDataSetChanged();
							handler.sendEmptyMessage(UIEventListener.EVENT_HIDE_BOTTON_MENU);
						} else if (receiveLayout.isShown()) {

							HashMap<String, String> map = new HashMap<String, String>();
							map.put("invoke", "deleteMail");
							map.put("userCode", MailApplication.userCode);
							map.put("password", MailApplication.passWord);
							map.put("mailIds", mailInfo.mailId);
							new HttpManage(HomeActivity.this, HomeActivity.this, map, 5);
							HomeActivity.this.dialog = Utils.createProgressDialog(HomeActivity.this,
									Utils.getLoadingMessage(HomeActivity.this, "删除邮件..."));
							HomeActivity.this.dialog.show();

						} else if (unreadLayout.isShown()) {
							if (selectedList_unread.size() > 0) {
								String mailIds = "";
								for (int i = 0; i < selectedList_unread.size(); i++) {
									if (i == (selectedList_unread.size() - 1)) {
										mailIds += selectedList_unread.get(i);
									} else {
										mailIds += selectedList_unread.get(i) + ",";
									}
								}

								HashMap<String, String> map = new HashMap<String, String>();
								map.put("invoke", "deleteMail");
								map.put("userCode", MailApplication.userCode);
								map.put("password", MailApplication.passWord);
								map.put("mailIds", mailIds);
								new HttpManage(HomeActivity.this, HomeActivity.this, map, 6);
								HomeActivity.this.dialog = Utils.createProgressDialog(HomeActivity.this,
										Utils.getLoadingMessage(HomeActivity.this, "删除邮件..."));
								HomeActivity.this.dialog.show();
							}
						} else if (sendLayout.isShown()) {
							// 删除数据库中的数据
							ArrayList<Long> timeMillises = new ArrayList<Long>();
							timeMillises.add(mailInfo.timeMillis);
							db.deleteSendMail(timeMillises);

							// 删除map集合中的数据
							for (int i = 0; i < mailInfoMapSend.size(); i++) {
								List<MailInfo> list = mailInfoMapSend.get(i);
								for (int j = 0; null != list && j < list.size(); j++) {
									if (mailInfo.timeMillis == list.get(j).timeMillis) {
										mailInfoMapSend.get(i).remove(j);
										break;
									}
								}
							}

							mailListAdapter_send.notifyDataSetChanged();
							handler.sendEmptyMessage(UIEventListener.EVENT_HIDE_BOTTON_MENU);
						}
						dialogInterface.dismiss();
					}
				}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				});
		dialog.show();
	}

	/**
	 * 每个子类的点击事件
	 */
	@Override
	public void onItemClicked(View parent, MailInfo mailInfo) {
		if (parent == listView_receive) {
			Intent intent = new Intent(HomeActivity.this, MailInfoActivity.class);
			intent.putExtra("mailId", mailInfo.mailId);
			startActivityForResult(intent, 11);
			if (mailInfo.readFlag) {
				mailInfo.readFlag = true;

				unreadNum--;
				// 将未读邮件的数量显示在文本框中
				showUnreadNumOnTextView();

				if (receiverAdapter != null) {
					receiverAdapter.notifyDataSetChanged();
				}
			}
		} else if (parent == listView_unread) {
			Intent intent = new Intent(HomeActivity.this, MailInfoActivity.class);
			intent.putExtra("mailId", mailInfo.mailId);
			startActivityForResult(intent, 12);
			if (mailInfo.readFlag) {
				mailInfo.readFlag = true;

				unreadNum--;
				// 将未读邮件的数量显示在文本框中
				showUnreadNumOnTextView();

				if (mailListAdapter_unread != null) {
					mailListAdapter_unread.notifyDataSetChanged();
				}
			}
		} else if (parent == listView_send) {
			Intent intent = new Intent(HomeActivity.this, MailInfoActivity.class);
			intent.putExtra("mailInfo", mailInfo);
			intent.putExtra("sendType", true);
			startActivityForResult(intent, 13);
		} else if (parent == listView_caogao) {
			Intent intent = new Intent(HomeActivity.this, MailActivity.class);
			intent.putExtra("mailInfo", mailInfo);
			intent.putExtra("mailType", 4);
			startActivityForResult(intent, 1);
		}
	}
}